<form id="form_add_datagrid_custom_in_m44" enctype="multipart/form-data" method="post" action="#" class="form form-add-datagrid-custom">
    <div class="wrapper-form">
        <dl class="row">
            <dt class="tit">
                <label><em>*</em>所在菜单</label>
            </dt>
            <dd class="opt">
                <input type="text" name="menu_id" class="input-txt" maxlength="50" id="form_input_menu_id_in_add_datagrid_custom_in_m44"/>
            </dd>
        </dl>
        <dl class="row">
            <dt class="tit">
                <label><em>*</em>数据表</label>
            </dt>
            <dd class="opt">
                <input type="text" name="table_id" class="input-txt" maxlength="50" id="form_input_table_id_in_add_datagrid_custom_in_m44"/>
            </dd>
        </dl>
        <dl class="row">
            <dt class="tit">
                <label><em>*</em>数据表名称</label>
            </dt>
            <dd class="opt">
                <input type="text" name="datagrid_name" class="input-txt" maxlength="50" />
            </dd>
        </dl>
        <dl class="row">
            <dt class="tit">
                <label>表格标识码</label>
            </dt>
            <dd class="opt">
                <input type="text" name="datagrid_code" class="input-txt readonly" maxlength="50" readonly="readonly"
                       id="form_input_datagrid_code_in_add_datagrid_custom_in_m44" />
            </dd>
        </dl>
    </div>
</form>
<script>
    $(function(){
        var subject = "add_datagrid_custom_in_m44";
        var formId = "#form_" + subject;
        var formInputIdMenuId= "#form_input_menu_id_in_" + subject;
        var formInputIdTableId = "#form_input_table_id_in_" + subject;
        var formInputIdDatagridCode = "#form_input_datagrid_code_in_" + subject;
        var optionDataTable = getTableOption();
        var optionDataMenu = getBottomMenuOption();
        var optionTableConfig = {
            data: optionDataTable,
            textField: "table_name",
            valueField: "id",
            width:'100%',
            onSelect:function(item){
                var selectTableName = item.table_name;
                var selectMenuId = $(formInputIdMenuId).combobox('getValue');
                var pageCode = selectTableName.replace('yj_', '') + '_m' + selectMenuId;
                $(formInputIdDatagridCode).val(pageCode);
            }
        };

        var optionConfigMenu = {
            data: optionDataMenu,
            textField: "menu_path",
            valueField: "id",
            width:'100%',
            onSelect:function(item){
                var selectMenuId = item.id;
                var selectTableName = $(formInputIdTableId).combobox('getText');
                if('undefined' !== selectTableName){
                    var pageCode = selectTableName.replace('yj_', '') + '_m' + selectMenuId;
                    $(formInputIdDatagridCode).val(pageCode);
                }
            }
        }
        $(formInputIdTableId).combobox(optionTableConfig);
        $(formInputIdMenuId).combobox(optionConfigMenu);
        //
        // $("#btn_submit_form_add_page_custom").click(function(){
        //     var formData = $(formId).serializeObject();
        //     console.log("form data:", formData);
        //     $.ajax({
        //         url: '/api/PageCustom/addPageCustom',
        //         async: false,
        //         type: 'post',
        //         data: formData,
        //         success: function (resp) {
        //             if (1 == resp.code) {
        //                 optionData = resp.data;
        //             }else{
        //                 layer.msg(resp.message);
        //             }
        //         }
        //     });
        // });
    });

    function getTableOption() {
        var optionData;
        $.ajax({
            url: '/api/Table/getTableOption',
            async: false,
            type: 'post',
            data: {},
            success: function (resp) {
                if (1 == resp.code) {
                    optionData = resp.data;
                }
            }
        });
        return optionData;
    }

    function getTableFieldOption(tableId) {
        var optionData;
        $.ajax({
            url: '/api/Table/getTableFieldOption',
            async: false,
            type: 'post',
            data: {table_id: tableId},
            success: function (resp) {
                if (1 == resp.code) {
                    optionData = resp.data;
                }
            }
        });
        return optionData;
    }
</script>